

//
//  ZHNetWorkingController.swift
//  999999新浪微博
//
//  Created by 陈华 on 15/12/19.
//  Copyright © 2015年 华锐. All rights reserved.
//网络工具类，负责所有的网络请求相关事。

import UIKit
import AFNetworking

class ZHNetWorkingController: AFHTTPSessionManager {
    
    //创建一个单例对象
    static let netWorking: ZHNetWorkingController = ZHNetWorkingController(baseURL: NSURL(string: "https://api.weibo.com"))
    
    let client_id = "1972890934"
    let client_secret = "f85f3bfa6c03d4f9efe345104af82fd0"
    let redirect_uri = "http://www.baidu.com//"
    
    ///通过code加载访问令牌
    func loadAccess_token(codeNew: String, finish: (resultt: [String:AnyObject]?, error: NSError?) -> ()){
        let parameters: NSDictionary? = [
            "client_id": client_id,
            "client_secret": client_secret,
            "grant_type": "authorization_code",
            "code":codeNew,
            "redirect_uri": redirect_uri
        ]
        self.responseSerializer.acceptableContentTypes?.insert("text/plain")
        POST("https://api.weibo.com/oauth2/access_token", parameters: parameters, success: { (_, result) -> Void in
            let result = result as? [String: AnyObject]//这里的类型转换有点烦躁
            finish(resultt:result , error: nil)
            }) { (_, error) -> Void in
                finish(resultt: nil, error: error)
                
        }
    }
    
}






